package com.cirkana.viewer.data;

import java.util.Date;
import java.util.Hashtable;

import com.cirkana.data.IDataRecord;
import com.cirkana.serial.bin.IBinarySerializable;
import com.cirkana.serial.text.ITextSerializable;

public abstract class LocalDataRecord implements IDataRecord, IBinarySerializable, ITextSerializable {

	protected Hashtable<String, Object> fields = new Hashtable<String, Object>();

	protected String getStringField(String column) {
		return (String) getField(column);
	}

	protected void setStringField(String column, String value) {
		setField(column, value);
	}

	protected Integer getIntegerField(String column) {
		return (Integer) getField(column);
	}

	protected void setIntegerField(String column, Integer value) {
		setField(column, value);
	}

	protected Date getDateField(String column) {
		return (Date) getField(column);
	}

	protected void setDateField(String column, Date value) {
		setField(column, value);
	}

	@Override
	public Object getField(String column) {
		Object v = this.fields.get(column);
		return dbNull.equals(v) ? null : v;
	}

	@Override
	public void setField(String column, Object value) {
		this.fields.put(column, value == null ? dbNull : value);
	}

	protected static final class DbNull {
	}

	private static DbNull dbNull = new LocalDataRecord.DbNull();
}
